<template>
  <div class="detail-wrapper">
    <view class="detail-top">
      <span
        v-if="noticeDetail.isTop === true"
        class="settop"
        style="margin-top: 6px;padding: 2px 0;"
      >置顶</span>
      <span class="notice-title">{{ noticeDetail.title }}</span>
    </view>
    <view class="detail-info">
      <span class="notice-author">{{ noticeDetail.createUserName }}</span>
      <span class="notice-time">{{ noticeDetail.gmtCreate | formatDateAll(noticeDetail.gmtCreate) }}</span>
    </view>
    <view class="notice-content" v-html="noticeDetail.contentHasStyle"></view>
    <view class="notice-author" style="padding-top: 10px;" v-if="file.length!==0">
      附件：
      <text style="font-size:12px;color:#9c9c9c">长按文件可复制地址</text>
    </view>
    <view
      style="margin-top:12px;font-size:12px;color:#9c9c9c"
      v-for="i in file"
      :key="i.name"
      @click="setClipboardData(i)"
    >{{i.name}}</view>
  </div>
</template>
<script>
import { findSysNoticeByUser } from "@/services/contract";
import { formatDateAll } from "@/utils/tools.js";
export default {
  filters: {
    formatDateAll: formatDateAll
  },
  data() {
    return {
      file: [],
      noticeId: "",
      noticeDetail: {}
    };
  },
  onLoad(options) {
    this.noticeId = options.id;
    this.getNoticeDetail(this.noticeId);
  },
  methods: {
    setClipboardData(e) {
      wx.setClipboardData({
        data: e.url,
        success(res) {
          wx.getClipboardData({
            success(res) {
              console.log(res.data); // data
            }
          });
        }
      });
    },
    getNoticeDetail(noticeId) {
      console.log(uni.getStorageSync("token"));
      findSysNoticeByUser(noticeId).then(res => {
        this.noticeDetail = res;
        // this.noticeDetail.contentHasStyle = this.noticeDetail.contentHasStyle.match(
        //   /token=(\S*)style/
        // );
        // this.noticeDetail.contentHasStyle = this.noticeDetail.contentHasStyle.replace(
        //   "?",
        //   `?token=${uni.getStorageSync("token")} " style`
        // );
        console.log(this.noticeDetail.contentHasStyle);
        this.file = JSON.parse(this.noticeDetail.file);
      });
    }
  }
};
</script>
